package com.example.demo.thread;

import java.util.concurrent.TimeUnit;

/**
 * TODO: 这里要写注释的!
 */
public class VolatileTest0 {
    public static boolean stop=false;

    public static void run() throws InterruptedException {

    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread1= new Thread(new Runnable() {
            @Override public void run() {
                int i=0;
                while(!stop){
                    System.out.println(Thread.currentThread().getName()+"i is: " + (++i));
                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        thread1.start();
        TimeUnit.SECONDS.sleep(3);
        stop=true;
    }
}
